<?php
/*
 * Copyright (c) 2021.  Liuhongbin All rights reserved.
 * @domain http://dkyx.cc
 * @author liuhongbin <514660094@qq.com>
 */

namespace hiduoke\base;


use Overtrue\EasySms\EasySms;
use Overtrue\EasySms\Strategies\OrderStrategy;

abstract class BaseSms extends BaseDriver
{

    public $gateways;

    public $smsConfig;

    public $config;

    /**
     * @inheritDoc
     */
    protected function initialize(array $config)
    {
        $this->smsConfig = [
            // HTTP 请求的超时时间（秒）
            'timeout'  => 5.0,
            // 默认发送配置
            'default'  => [
                // 网关调用策略，默认：顺序调用
                'strategy' => OrderStrategy::class,
                // 默认可用的发送网关
                'gateways' => [],
            ],
            // 可用的网关配置
            'gateways' => []
        ];
        $this->config = $config;
    }


    /**
     * @return mixed
     */
    public function getGateways()
    {
        return $this->gateways;
    }

    /**
     * @param mixed $gateways
     */
    public function setGateways($name, $gateways_config)
    {
        $this->smsConfig['default']['gateways'][] = $name;
        $this->smsConfig['gateways'][$name] = $gateways_config;
        $this->gateways = new EasySms($this->smsConfig);
        return $this->gateways;
    }

    abstract public function send($to, $message);
}